/**************************************************************
  > File Name: 605.c
  > Author: LuoLiang
 **************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

bool canPlaceFlowers(int* flowerbed, int flowerbedSize, int n)
{
	int i;
	int *flag = (int *)calloc(flowerbedSize, sizeof(int));

	if (flowerbedSize == 1)
	{
		if (flowerbed[0] == 0)
			return true;
		return false;
	}

	for (i = 0; i < flowerbedSize; i++)
	{
		if (flowerbed[i] == 1)
		{
			flag[i] = 1;
		}
		else 
		{
			if ((i - 1 == -1 && flowerbed[i+1] == 0) || (i - 1 >= 0 && flag[i-1] == 0 && \
									i + 1 == flowerbedSize && flowerbed[i-1] == 0) || \
						   	(flowerbed[i-1] == 0 && flag[i-1] == 0 && flowerbed[i+1] == 0))
			{
				flag[i] = 1;
				n--;
			}
		}
	}
	if (n > 0)
		return false;
	return true;
}

int main(int argc, char **argv)
{
	int a[] = {0,1,0};
	int ret;

	ret = canPlaceFlowers(a, sizeof(a)/sizeof(*a), 1);
	printf("%d\n",ret);
    exit(0);
}
